package com.example.springbootbabyu.controller;

import com.example.springbootbabyu.utils.ResultUtil;
import com.example.springbootbabyu.entity.*;
import com.example.springbootbabyu.service.HomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能
 * 作者：梦天
 * 日期：2025/4/14 8:09
 */
@RestController
@RequestMapping("/home")
@CrossOrigin
@Slf4j
public class HomeController {
    @Autowired
    private HomeService homeService;
    @GetMapping("/category/head")
    public ResultUtil homeCategoryHead() {
        try {
            log.info("获取首页分类头部数据");
            return ResultUtil.success(1, "操作成功", homeService.getHomeCategoryHead());
        } catch (Exception e) {
            log.error("获取首页分类头部数据失败", e);
            return ResultUtil.error(500, "获取首页分类头部数据失败");
        }
    }
    @GetMapping("/hot")
    public ResultUtil homeHot() {
        try {
            log.info("获取首页热门数据");
            return ResultUtil.success(1, "操作成功", homeService.getHomeHot());
        } catch (Exception e) {
            log.error("获取首页热门数据失败", e);
            return ResultUtil.error(500, "获取首页热门数据失败");
        }
    }
    @GetMapping("/brand")
    public ResultUtil homeBrand() {
        try {
            log.info("获取首页品牌数据");
            return ResultUtil.success(1, "操作成功", homeService.getHomeBrand());
        } catch (Exception e) {
            log.error("获取首页品牌数据失败", e);
            return ResultUtil.error(500, "获取首页品牌数据失败");
        }
    }
    @GetMapping("/banner")
    public ResultUtil homeBanner(@RequestParam(value = "distributionSite", required = false, defaultValue = "1") Integer distributionSite) {
        try {
            log.info("获取首页轮播图数据");
            return ResultUtil.success(1, "操作成功", homeService.getHomeBanner());
        } catch (Exception e) {
            log.error("获取首页轮播图数据失败", e);
            return ResultUtil.error(500, "获取首页轮播图数据失败");
        }
    }
    @GetMapping("/new")
    public ResultUtil homeNew() {
        try {
            log.info("获取首页新品数据");
            return ResultUtil.success(1, "操作成功", homeService.getHomeNew());
        } catch (Exception e) {
            log.error("获取首页新品数据失败", e);
            return ResultUtil.error(500, "获取首页新品数据失败");
        }

    }
    @GetMapping("/goods")
    public ResultUtil homeGoods(){
        try {
            log.info("获取首页商品数据");
            return ResultUtil.success(1, "操作成功", homeService.getHomeGoods());
        } catch (Exception e) {
            log.error("获取首页商品数据失败", e);
            return ResultUtil.error(500, "获取首页商品数据失败");
        }
    }
}
